﻿Imports System.Xml
Imports log4net.Config
Imports log4net
Imports VPager.Settings

Class Application

    ' Application-level events, such as Startup, Exit, and DispatcherUnhandledException
    ' can be handled in this file.

    Private Const LOG_CONFIG_FILE As String = "Logger.config"

    Private Shared sInstance As Application
    Private mLog As ILog

    Public Shared ReadOnly Property AppVersion As String
        Get
            Return getInstance.getVersion
        End Get
    End Property

    Public Sub New()
        configureLogging()


        mLog.Debug("Application Class instantiated. Logging configured.")

        sInstance = Me

    End Sub

    Shared Function getInstance() As Application
        Return sInstance
    End Function

    Private Function getVersion() As String
        Dim version As String = "!ERROR!"
        ' Parse the version from the app.manifest XML file
        ' There shoudl be an easier way to get the Publish Verison :-(
        Try
            Dim m_xmld = New XmlDocument()
            m_xmld.Load(Forms.Application.ExecutablePath & ".manifest")
            Dim v = m_xmld.ChildNodes.Item(1).ChildNodes.Item(0).Attributes.GetNamedItem("version").Value
            If v <> "" Then
                version = v
            End If
        Catch ex As Exception
        Finally
        End Try
        Return version
    End Function

    Public Sub configureLogging()
        'Configure Logging


        XmlConfigurator.Configure(New System.IO.FileInfo(LOG_CONFIG_FILE))

        ' TODO: Use the Log File setting to set the log output file
        Dim logfile As String = SettingsManager.getValue(SettingKey.LOG_FILE)
        ' TODO: Use the Log Level setting to set the Logger level
        Dim logLevel As Integer = SettingsManager.getValue(SettingKey.LOG_LEVEL)

        mLog = LogManager.GetLogger(Me.GetType())
    End Sub


End Class
